<?php
/**
 * Image Factory
 * 
 * Supports jpeg, gif and png images. Gets mime type from getimagesize()
 */   
class ImageFactory
{
  public static function factory($path)
  {
    if($imageInfos = getimagesize($path))
    {
      switch($imageInfos['mime'])
      {
        case "image/jpeg":
          return new Jpg($path);
          break;
        case "image/png":
          return new Png($path);
          break;
        case "image/gif":
          return new Gif($path);
          break;
        default:
          throw new ImageException('format invalide');
      }
    }
    else
    {
      throw new ImageException('format invalide');
    }
  }
}
?>
